/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Base for creating a custom VGUI class; remove the functions you don't use.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/



local PANEL = {}

function PANEL:Init()
	//Create controls here
	
	
	self.TAM = 5
	self.TARGET = ""
	self.CPTEXT = ""
	
	self:ShowCloseButton( false )
	self:SetTitle( " " )
	
	local TPanel = vgui.Create( "DPanel", self )
		
		self.TPanel = TPanel
	
	local TransAmount = vgui.Create( "DTextEntry", TPanel )	//Editing problems
	local SP = self
		TransAmount:SetNumeric( true )
		TransAmount:SetEnterAllowed( true )
		TransAmount:SetValue( self.TAM )
		function TransAmount:OnTextChanged()
			SP.TAM = TransAmount:GetValue()
		end
		
		self.TransAmount = TransAmount
		
		
	local CPoints = vgui.Create( "DLabel", TPanel )
		CPoints:SetText( self.CPTEXT )
	
		self.CPoints = CPoints
		
		
	local GIVEB = vgui.Create( "DButton", TPanel )
		GIVEB:SetText( "Trade" )
		function GIVEB:DoClick()
			if SP.TARGET != "" then
				RunConsoleCommand( "PointTransaction", SP.TARGET, SP.TAM )
				LocalPlayer():PrintMessage( HUD_PRINTTALK, "Transaction Successful." )
				SP:Remove()
			else
				LocalPlayer():PrintMessage( HUD_PRINTTALK, "The selected player is invalid." )
				RunConsoleCommand( "FinishTransaction" )
				SP:Remove()
			end
		end
		
		self.GIVEB = GIVEB
		
		
	local CLOSEB = vgui.Create( "DButton", TPanel )
		CLOSEB:SetText( "Exit" )
		function CLOSEB:DoClick()
			LocalPlayer():PrintMessage( HUD_PRINTTALK, "Transaction Canceled." )
			RunConsoleCommand( "FinishTransaction" )
			SP:Remove()
		end
		
		self.CLOSEB = CLOSEB
		
		self:SetSize( 200, 110 )
		self:Center()
		
		//self.TPanel:StretchToParent( 0, 0, 0, 0 )

end

function PANEL:PerformLayout()
	// Let's make sure we perform the layout of the class this panel is based on here as well.
	//self.BaseClass.PerformLayout( self )
	
	self.TPanel:StretchToParent( 0, 0, 0, 0 )
	
	self.TransAmount:Center()
	self.TransAmount:AlignTop( 5 )
	
	self.GIVEB:SetSize( 50, 25 )
	self.GIVEB:AlignBottom( 5 )
	self.GIVEB:AlignLeft( 5 )
	
	self.CLOSEB:SetSize( 50, 25 )
	self.CLOSEB:AlignBottom( 5 )
	self.CLOSEB:AlignRight( 5 )

end

function PANEL:Paint()
	//Do Painting here
	
	//self.BaseClass.Paint( self )
	
	draw.RoundedBox( 4, 0, 0, self:GetWide(), self:GetTall(), Color( 0, 0, 0, 150 ) )

end

function PANEL:PaintOver()

	//Paint over self and child elements here.

end

function PANEL:Think()

	//Think stuff here

	self.CPoints:SetText( self.CPTEXT )
	self.CPoints:SizeToContents()
	self.CPoints:Center()
	self.CPoints:MoveBelow( self.TransAmount, 5 )
	
end

function PANEL:OnCursorEntered()

	//Do stuff when the cursor enters the panel

end

function PANEL:OnCursorExited()

	//Do Stuff when the cursor leaves the panel

end

function PANEL:OnMouseWheeled()

	//Do stuff when you wheel the mouse on this panel

end

function PANEL:OnMousePressed()

	//Do stuff when you press the mouse on this panel

end

function PANEL:OnMouseReleased()

	//Do stuff when you release the mouse on this panel

end

function PANEL:OnKeyCodePressed()

	//Do stuff when using keys from the keyboard on this panel. This hook uses the keycode enumerations
	//http://wiki.garrysmod.com/?title=P.OnKeyCodePressed	For more information

end

function PANEL:ActionSignal()

	//This is called on the parent frame when a child VGUI element is used. The key corresponds to what is set by Panel.SetCommand.
	//From the wiki
	
end

function PANEL:OnCursorMoved()

	//From the wiki
	//Called whenever the the mouse is moved within the panel.

end

function PANEL:DoClick()

	//For button type panels, use this. Called when you click the button.

end


//Register syntax - Desired element name, Panel to use, base class of the new element.
vgui.Register( "TransactionMenu", PANEL, "DFrame" )


function PlayerUseUMHOOK( um )
	local UID = um:ReadString()
	
	local OptionMenu = vgui.Create( "DMenu" )
		OptionMenu:AddOption( "Points Transaction", function()
			local TRANMENU = vgui.Create( "TransactionMenu" )
				TRANMENU.TARGET = UID
				TRANMENU.CPTEXT = "Your Points: " .. LocalPlayer():GetNetworkedInt( "points" )
				//TRANMENU.TransAmount:SetValue( 5 )
				TRANMENU:MakePopup()
			end )
		OptionMenu:AddOption( "Exit", function() RunConsoleCommand( "FinishTransaction" ) OptionMenu:Remove() end )
		OptionMenu:SizeToContents()
		OptionMenu:Center()
		OptionMenu:MakePopup()

end
usermessage.Hook( "PlayerUseMESS", PlayerUseUMHOOK )

